package com.ruoyi.api.controller.fission;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.business.domain.vo.fission.api.SceneInfoVO;
import com.ruoyi.business.domain.vo.fission.api.WecomChatGroupVO;
import com.ruoyi.business.service.fission.ITbWecomChatGroupFissionSceneService;
import com.ruoyi.business.service.fission.ITbWecomChatGroupFissionService;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Validated
@Api(value = "小程序群裂变活动控制器", tags = {"小程序群裂变活动控制器"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/miniapp/fission")
public class ApiFissionController extends AbstractApiController {

    @Resource
    private ITbWecomChatGroupFissionSceneService tbWecomChatGroupFissionSceneService;

    @Resource
    private ITbWecomChatGroupFissionService tbWecomChatGroupFissionService;


    /**
     * 根据小程序场景值查询分享小程序用户 与 群裂变活动 信息
     */
    @ApiOperation("根据场景值查询群裂变活动信息")
    @GetMapping("/query-scene-info")
    public R<SceneInfoVO> getUserInfoDetail(@ApiParam("scene小程序场景值") @RequestParam(required = true) String scene) {
        return R.ok(tbWecomChatGroupFissionSceneService.queryByScene(getUserId(), scene));
    }

    /**
     * 查询群裂变活动可用企微入群二维码
     */
    @ApiOperation("查询群裂变活动可用企微入群二维码")
    @GetMapping("/query-chat-group-qrcode")
    public R<WecomChatGroupVO> queryChatGroupQrCode(@ApiParam("scene小程序场景值") @RequestParam(required = true) String scene) {
        return R.ok(tbWecomChatGroupFissionService.queryChatGroupQrCode(getUserId(), scene));
    }

    /**
     * 用户生成分享活动小程序二维码
     */
    @ApiOperation("分享裂变活动小程序二维码 ->后端分享生成小程序二维码")
    @GetMapping("/share-qr-code")
    public R<String> shareQrCode(
        @ApiParam("env 正式版:release 体验版:trial 开发版:develop") @RequestParam(required = true) String env,
        @ApiParam("群裂变活动id") @RequestParam(required = true) Long fissionId) {
        return R.ok(tbWecomChatGroupFissionService.shareQrCode(getUserId(), fissionId, env));
    }

    /**
     * 生成分享活动场景值
     */
    @ApiOperation("生成我的分享小程序场景值 ->前端分享")
    @GetMapping("/generate-scene")
    public R<String> generateMyScene(@ApiParam("群裂变活动id") @RequestParam(required = true) Long fissionId) {
        return R.ok(tbWecomChatGroupFissionService.generateMyScene(getUserId(), fissionId));
    }





}
